//
// Created by wkm on 2023-12-09.
//
#include "read_vectors.h"
#include "check_results.h"
#include "../../ModelingExample/ShiftRegister/usr.h"

int sc_main(int argc, char *argv[]) {
    sc_signal<bool> clear, left_in, right_in;
    sc_signal<sc_uint<SEL_WIDTH>> sel_op;
    sc_signal<sc_uint<WIDTH>> data_in, usr_out, expected_usr_out;

    // 生成的时钟
    sc_clock clock("usr_clock", 2);

    // 在施加激励之前，实例引用被测设计
    usr u1("usr_u1");
    u1.clk(clock);
    u1.clr(clear);
    u1.lin(left_in);
    u1.rin(right_in);
    u1.select(sel_op);
    u1.par_in(data_in);
    u1.q(usr_out);

    // 实例引用读取向量模块
    read_vectors rv("read_vectors_rv");
    rv.read_clk(clock);
    rv.read_clear(clear);
    rv.read_left_in(left_in);
    rv.read_right_in(right_in);
    rv.read_sel_op(sel_op);
    rv.read_data_in(data_in);
    rv.read_usr_out(expected_usr_out);

    // 实例引用检查模块
    check_result cr1("check_results_cr1");
    cr1.check_clk(clock);
    cr1.expected_out(expected_usr_out);
    cr1.actual_out(usr_out);

    //记录仿真波形
    sc_trace_file *tf = sc_create_wif_trace_file("usrout");
    sc_trace(tf, clock, "clock");
    sc_trace(tf, clear, "clear");
    sc_trace(tf, left_in, "left_in");
    sc_trace(tf, right_in, "right_in");
    sc_trace(tf, sel_op, "sel_op");
    sc_trace(tf, data_in, "data_in");
    sc_trace(tf, usr_out, "usr_out");

    sc_start(); // 参数应该是-1，一直运行。尽管如此，仿真会由于在模块read_vectors中的sc_stop()方法而停止

    sc_close_wif_trace_file(tf);
    return (0);
}